package com.bjpowernode.appdata;
import com.bjpowernode.beans.ClassRoom;
import com.bjpowernode.beans.Stu;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

public class MyApp {

    public static void main(String[] args) {

        ClassRoom classRoom=new ClassRoom(1,"SZ2208");
        Stu stu = new Stu(3000, "hzj", 95,classRoom);
        String path = "d:\\stu3.data";

        try {
            FileOutputStream fileOutputStream = new FileOutputStream(path);
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
            //如果对象所在类没有序列化，则操作对象流会报错
            //序列化是指把对象的内容【属性的结果数据进行流化】
            //java.io.NotSerializableException: com.bjpowernode.beans.Stu
            objectOutputStream.writeObject(stu);
            objectOutputStream.flush();
            objectOutputStream.close();
            fileOutputStream.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
